﻿#pragma once

#include <QString>
#include <QVector>
#include <QSerialPort>
#include <QMessageBox>
#include <QCryptographicHash>
#include <QtNetwork/QNetworkInterface>

#define FLUSH_INTERVAL_TIME 2000

struct BatteryInfoRom
{
	unsigned int cellNum;
	unsigned int tempNum;
	unsigned int runTimeDay;
	unsigned int runTimeH;
	unsigned int runTimeM;
	unsigned int runTimeS;
	unsigned int soh;
	unsigned int voltage;
	unsigned int curCade;
	unsigned int predsgTemp;
	unsigned int balTmp;
	unsigned int MosTemp;
	unsigned int tmax;
	unsigned int tmin;
	unsigned int tmaxNo;
	unsigned int tminNo;
	unsigned int vmax;
	unsigned int vmin;
	unsigned int vmaxNo;
	unsigned int vminNo;
	unsigned int rsoc;
	unsigned int fcc;
	unsigned int rc;
	unsigned int cycleCount;
	unsigned int status;
	unsigned int protectReason;
	unsigned int alarmLevel;
	unsigned int vccmr;
	unsigned int gndmr;
	unsigned int pack_RWH;
	unsigned int vMaxMinDiff;
	unsigned int vSum;
	unsigned int tMaxMinDiff;
	unsigned int tsum;
	unsigned int ctrlBit;
	QVector<QString> protectInfoVec;
};

struct BatteryDetailInfoRom
{
	unsigned int allTemp[300];
	unsigned int allVCell[300];
	unsigned int balCur[300];
};

struct SerialPortInfo
{
	QString portname;
	QSerialPort::BaudRate baudRate;

};

struct MetaProtectParam
{
	float protectValue;
	float protectDelay;
	float releaseValue;
	float releaseDelay;
};

struct ProtectParamInfo
{
	MetaProtectParam tov;
	MetaProtectParam ov;
	MetaProtectParam tuv;
	MetaProtectParam uv;
	MetaProtectParam otd;
	MetaProtectParam otc;
	MetaProtectParam utd;
	MetaProtectParam utc;
	MetaProtectParam ocd1;
	MetaProtectParam ocd2;
	MetaProtectParam occ;
	MetaProtectParam otMos;
	uint sc;
};

struct FactoryParamInfo
{
	uint UART1_ADDR;
	uint UART1_Bound;
	uint UART2_ADDR;
	uint UART2_Bound;
	uint UART3_ADDR;
	uint UART3_Bound;
	uint UART4_ADDR;
	uint UART4_Bound;
	uint CAN1_BPS;
	uint CAN2_BPS;
	uint CAN3_BPS;
	uint CAN4_BPS;
	uint PACK_IterationFcc;
	uint CHG_Voltage;
	uint CHG_Current;
	uint REALRC_H;
	uint REALRC_L;
	uint OFFECT_I;
	uint SampRes;
	uint HOT_MODE;
	uint HOT_ON_TEMP;
	uint HOT_OFF_TEMP;
	uint CHG_DSG_MODE;
	uint KEY_MODE;
	uint CD_ForceTime;
	uint Battery_Type;
	uint Bal_Res;
	uint Bal_Type;
	uint Bal_ONVol;
	uint Bal_Vdiff;
	uint LowPower_BEEP_EN;
	uint AFE[30];
	uint ALLTEMPNUM[30];

};

typedef struct BatteryInfoRom BatteryInfoRom;
typedef struct BatteryDetailInfoRom BatteryDetailInfoRom;
typedef struct SerialPortInfo SerialPortInfo;
typedef struct MetaProtectParam MetaProtectParam;
typedef struct ProtectParamInfo ProtectParamInfo;

namespace GD{
//quint16 calculateCRC16(const QByteArray &data)
//{
//	quint16 crc = 0xFFFF;
//	QDataStream stream(data);
//	while (!stream.atEnd()) {
//		quint8 byte;
//		stream >> byte;
//		crc ^= (quint16)byte;
//		for (int i = 0; i < 8; ++i) {
//			if (crc & 0x0001) {
//				crc >>= 1;
//				crc ^= 0xA001;
//			}
//			else {
//				crc >>= 1;
//			}
//		}
//	}
//	return crc;
//}

}